package br.com.fabrica.aid.aid_fabrica.view;

import javax.faces.model.SelectItem;
import javax.inject.Inject;
import br.com.fabrica.aid.aid_fabrica.business.ColaboradorBC;
import br.com.fabrica.aid.aid_fabrica.domain.Colaborador;
import br.com.fabrica.aid.aid_fabrica.domain.Curso;
import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.stereotype.ViewController;
import br.gov.frameworkdemoiselle.template.AbstractEditPageBean;
import br.gov.frameworkdemoiselle.transaction.Transactional;

@ViewController
@PreviousView("./colaborador_list.xhtml")
public class ColaboradorEditMB extends AbstractEditPageBean<Colaborador, Long> {
	private static final long serialVersionUID = 1L;
	@Inject
	private ColaboradorBC colaboradorBC;
	
	@Override
	@Transactional
	public String delete() {
		this.colaboradorBC.delete(getId());
		return getPreviousView();
	}

	@Override
	@Transactional
	public String insert() {
		this.colaboradorBC.insert(getBean());
		return getPreviousView();
	}

	@Override
	@Transactional
	public String update() {
		this.colaboradorBC.update(getBean());
		return getPreviousView();
	}

	@Override
	protected void handleLoad() {
		setBean(this.colaboradorBC.load(getId()));
	}

	public SelectItem[] getCursoValues() {
		SelectItem[] items = new SelectItem[Curso.values().length];
		int i = 0;
		for (Curso c : Curso.values()) {
			items[i++] = new SelectItem(c, c.getNome());
		}
		return items;
	}

}